<?php

namespace tools;

class Participle
{
    public function __construct()
    {
        vendor("phpanalysis2_0.phpanalysis",'.class.php');
    }

    //获取分词
    public function getParticiple($str){
        \PhpAnalysis::$loadInit = false;
        $pa = new \PhpAnalysis();
        //载入词典
        $pa->LoadDict();
        //执行分词
        $pa->SetSource($str);
        $pa->resultType = 2;
        $pa->differMax = true;
        $pa->unitWord = true;
        $pa->differFreq = true;
        $pa->StartAnalysis( true );
        $okresult = $pa->GetFinallyResult(' ', false);
        return $okresult;
    }

    //获取关键字
    public function getParticipleKeyword($str,$len = 5){
        \PhpAnalysis::$loadInit = false;
        $pa = new \PhpAnalysis();
        //载入词典
        $pa->LoadDict();
        //执行分词
        $pa->SetSource($str);
        $pa->resultType = 2;
        $pa->differMax = true;
        $pa->unitWord = true;
        $pa->differFreq = true;
        $pa->StartAnalysis( true );
        $okresult = $pa->GetFinallyKeywords($len);
        return $okresult;
    }
}